class QuestionPoolsController < ApplicationController
  before_filter :login_required, :except => :index

  def index
    @cur = session[:current_question_pool]
    @question_pools = Category.find :all, :conditions => ['parent_id = ?', 0]
  end
  
  def select
    session[:current_question_pool] = Category.find(params[:id])
    redirect_back_or_default questionnaires_path
  end
  
  def new
    @category = Category.new
  end
  
  def create
    @category = Category.new params[:category]
    @category.creator_id = current_user
    @category.parent_id = 0
    if @category.save
      flash[:notice] = 'Question pool successfully added'
      redirect_to question_pools_path
    else
      render :action => :new
    end
  end
   
  def edit
    @category = Category.find params[:id]
  end
  
  def update
    @category = Category.find params[:id]
    if @category.update_attributes(params[:category])
      flash[:notice] = 'Question pool successfully updated'
      redirect_to question_pools_path
    else
      render :action => :new
    end
  end
end